<?php
namespace Hdphp\Libs;
class App{
    public static function run(){
        //初始化框架
        self::init();
        //如果没有自动载入函数
        spl_autoload_register([__CLASS__,"auto"]);
        App::autoRun();
    }
    private static function auto($cname){
        if(substr($cname,-10)=="Controller"){
            $path = "App/" . str_replace("\\","/" , $cname). ".php";
        }else{
            $path = str_replace("\\","/" ,$cname ) . ".php";
        }
        require $path;
    }
    private static function autoRun(){
        $m = MODULE;//地址栏请求的哪一个模块
        $c = CONTROLLER;//地址栏请求的哪一个控制器
        $a = ACTION;//地址栏请求的哪一个方法
        $controller = "\\{$m}\Controller\\{$c}Controller";
        $obj = new $controller;
        $obj->$a();
    }
    private static function init(){
        //GET['m']获取操作的模块
        $m = isset($_GET['m']) ? $_GET['m'] : "Home";
        define("MODULE",$m );//定义常量
        $c = isset($_GET['c']) ? $_GET['c'] : "view";
        define("CONTROLLER",$c );
        $a = isset($_GET['a']) ? $_GET['a'] : "Index";
        define("ACTION",$a );
        //配置项加载
        //先加载系统
        $systemConfig = include "\Hdphp\Common\Config.php";
        C($systemConfig);
        //设置时区，从配置项进行操作
        $userConfig = include "App/Home/Config/Config.php";
        C($userConfig);
       // date_default_timezone_set(C("TIMEZONE"));
        // var_dump(C('TIMEZONE'));die;
        date_default_timezone_set(C("TIMEZONE"));

        //开启session
        session_id() || session_start();
    }

}
